package cz.tomasdvorak.cars.url;

import cz.tomasdvorak.cars.dto.Vehicle;
import org.apache.wicket.RequestCycle;
import org.apache.wicket.ResourceReference;

public class VehicleImageUrlCreator implements UrlCreator<Vehicle> {

    private String defaultImage;

    public String create(Vehicle object) {
        return create(object, false);
    }

    public String create(Vehicle object, boolean thumbnail) {
        if (object.hasImage()) {
            ResourceReference imageResource = new ResourceReference("imageResource");
            return RequestCycle.get().urlFor(imageResource) + "?id=" + object.getId() + (thumbnail
                    ? "&thumbnail=1" : "");
        } else {
            return defaultImage;
        }
    }

    public void setDefaultImage(String defaultImage) {
        this.defaultImage = defaultImage;
    }
}
